Skip to main content

Generating Functions


Ordinary Generating Functions

Recurrence Relations and Generating Functions

Definition

Let {fn}n0\left\{f_n\right\}_{n \geq 0} be a sequence of real numbers. Then the formal power series F(x)=n0fnxnF(x)=\sum_{n \geq 0} f_n x^n is called the ordinary generating function of the sequence {fn}n0\left\{f_n\right\}_{n \geq 0}.

Example

Let an+2=3an+12ana_{n+2}=3 a_{n+1}-2 a_n if n0n \geq 0, and let a0=0a_0=0, and let a1=1a_1=1. Find an explicit formula for ana_n.

Solution

Let G(x)=n0anxnG(x)=\sum_{n \geq 0} a_n x^n. Multiply both sides of the recurrence relation by xn+2x^{n+2}, and sum over all natural numbers nn, to get

n0an+2xn+2=3n0an+1xn+22n0anxn+2,\sum_{n \geq 0} a_{n+2} x^{n+2}=3 \sum_{n \geq 0} a_{n+1} x^{n+2}-2 \sum_{n \geq 0} a_n x^{n+2},

which is equivalent to

G(x)x=3xG(x)2x2G(x).G(x)-x=3 x G(x)-2 x^2 G(x) .

Expressing G(x)G(x), we get

G(x)=x13x+2x2.G(x)=\frac{x}{1-3 x+2 x^2} .

The denominator of the right-hand side is again a quadratic polynomial. Note that 13x+2x2=(x1)(2x1)1-3 x+2 x^2=(x-1)(2 x-1). Therefore, we are going to find real numbers AA and BB so that

G(x)=x13x+2x2=Ax1+B2x1.G(x)=\frac{x}{1-3 x+2 x^2}=\frac{A}{x-1}+\frac{B}{2 x-1} .

After rearranging, we get

x=(2A+B)x(A+B).x=(2 A+B) x-(A+B) .

Two polynomials are the same if and only if their corresponding coefficients are the same. Therefore, it follows that 2A+B=12 A+B=1, and A+B=0A+B=0. So A=1A=1, and B=1B=-1. Consequently,

G(x)=x13x+2x2=11x+112x.G(x)=\frac{x}{1-3 x+2 x^2}=\frac{-1}{1-x}+\frac{1}{1-2 x} .

Both terms on the right-hand side are very easy to expand now. So

G(x)=n0xn+n02nxn=n0(2n1)xnG(x)=-\sum_{n \geq 0} x^n+\sum_{n \geq 0} 2^n x^n=\sum_{n \geq 0}\left(2^n-1\right) x^n

and therefore, an=2n1a_n=2^n-1.

Products of Generating Functions

Lemma

Let {an}n0\left\{a_n\right\}_{n \geq 0} and {bn}n0\left\{b_n\right\}_{n \geq 0} be two sequences, and let A(x)=A(x)= n0anxn\sum_{n \geq 0} a_n x^n, and B(x)=n0bnxnB(x)=\sum_{n \geq 0} b_n x^n be their respective generating functions. Define cn=i=0naibnic_n=\sum_{i=0}^n a_i b_{n-i}, and let C(x)=n0cnxnC(x)=\sum_{n \geq 0} c_n x^n. Then

A(x)B(x)=C(x)A(x) B(x)=C(x)

In other words, the coefficient of xnx^n in A(x)B(x)A(x) B(x) is cn=i=0naibnic_n=\sum_{i=0}^n a_i b_{n-i}.

Proof

When we multiply the infinite sum A(x)=a0+a1x+a2x2+A(x)=a_0+a_1 x+a_2 x^2+\cdots and the sum B(x)=b0+b1x+b2x2+B(x)=b_0+b_1 x+b_2 x^2+\cdots, we multiply each term of the first sum by each term of the second sum, then add all these products. So a typical product is of the form aixibjxja_i x^i \cdot b_j x^j. The exponent of xx in this product will be nn if and only if j=nij=n-i, and the claim follows.

Theorem (The Product Formula)

Let ana_n be the number of ways to build a certain structure on an nn-element set, and let bnb_n be the number of way to build another structure on an nn-element set. Let cnc_n be the number of ways to separate the set [n][n] into the intervals S={1,2,,i}S=\{1,2, \cdots, i\} and T={i+1,i+2,,n}T=\{i+1, i+2, \cdots, n\}, (the intervals SS and TT are allowed to be empty), and then to build a structure of the first kind on SS, and a structure of the second kind on TT. Let A(x),B(x)A(x), B(x), and C(x)C(x) be the respective generating functions of the sequences {an},{bn}\left\{a_n\right\},\left\{b_n\right\}, and {cn}\left\{c_n\right\}. Then

A(x)B(x)=C(x)A(x) B(x)=C(x) \text {. }

Proof

There are aia_i ways to build a structure of the first kind on SS, and bnib_{n-i} ways to build a structure of the second kind on TT. This is true for all ii, as long as 0in0 \leq i \leq n. Therefore, cn=i=0naibnic_n=\sum_{i=0}^n a_i b_{n-i}, and our claim follows from the Lemma.

Example I

If p(n)p(n) denotes the number of partitions of the integer nn, then

n0p(n)xn=k=111xk=(1+x+x2+x3+)(1+x2+x4+x6+)(1+x3+x6+x9+).\begin{gathered} \sum_{n \geq 0}^{\infty} p(n) x^n=\prod_{k=1}^{\infty} \frac{1}{1-x^k} \\ =\left(1+x+x^2+x^3+\cdots\right)\left(1+x^2+x^4+x^6+\cdots\right)\left(1+x^3+x^6+x^9+\cdots\right) \cdots . \end{gathered}

Solution

Same as the proof of the previous example, just here there is no limit on the size of the parts, and therefore, there are infinitely many parentheses on the right-hand side.

Example II

The number podd (n)p_{\text {odd }}(n) of partitions of nn into odd parts is equal to the number pd(n)p_d(n) of partitions of nn into all distinct parts.

Solution

The crucial idea is this. It suffices to show that the generating functions of the two sequences are equal. It is clear that

F(x)=n0podd (n)xn=i1i idd 11xiF(x)=\sum_{n \geq 0} p_{\text {odd }}(n) x^n=\prod_{\substack{i \geq 1 \\ i \text { idd }}} \frac{1}{1-x^i}

and

G(x)=n0pd(n)xn=i1(1+xi)=i11x2i1xi.G(x)=\sum_{n \geq 0} p_d(n) x^n=\prod_{i \geq 1}\left(1+x^i\right)=\prod_{i \geq 1} \frac{1-x^{2 i}}{1-x^i} .

Note that after cancellations, the denominator of G(x)G(x) will contain (1xi)\left(1-x^i\right) if and only if ii is odd, and will therefore be the same as the denominator of F(x)F(x). As both numerators are equal to 11, the proof follows.


Exponential Generating Functions

Definition

Let {fn}n0\left\{f_n\right\}_{n \geq 0} be a sequence of real numbers. Then the formal power series F(x)=n0fnxnn!F(x)=\sum_{n \geq 0} f_n \frac{x^n}{n !} is called the exponential generating function of the sequence {fn}n0\left\{f_n\right\}_{n \geq 0}.

Example I

Let kk be a fixed positive integer. Find the exponential generating function Sk(x)=nkS(n,k)xn/nS_k(x)=\sum_{n \geq k} S(n, k) x^n / n ! of the Stirling numbers S(n,k)S(n, k) of the second kind.

Solution

To obtain a partition of [n][n] into kk blocks, we need to partition [n][n] into kk nonempty blocks, and then "do nothing" on each of those blocks. There is one way to do nothing on any nonempty block, therefore, each task has generating function

A(x)=k1xkk!=ex1.A(x)=\sum_{k \geq 1} \frac{x^k}{k !}=e^x-1 .

If the order of the blocks in a partition mattered, we could simply say that the generating function of the combined task is Ak(x)A^k(x) by the Product formula. However, the order of the blocks does not matter, therefore

Sk(x)=1k!(ex1)kS_k(x)=\frac{1}{k !}\left(e^x-1\right)^k

We can now get an explicit formula for S(n,k)S(n, k) by computing the coefficient of xn/nx^n / n ! in Sk(x)S_k(x). A particularly useful property of exponential generating functions is that their derivatives are very easy to describe. Indeed, (xn+1(n+1)!)=xnn!\left(\frac{x^{n+1}}{(n+1) !}\right)^{\prime}=\frac{x^n}{n !}, and therefore

(n0anxnn!)=n0an+1xnn!.\left(\sum_{n \geq 0} a_n \frac{x^n}{n !}\right)^{\prime}=\sum_{n \geq 0} a_{n+1} \frac{x^n}{n !} .

The following example makes good use of this observation.

Example II

Let B(x)B(x) be the exponential generating function of the Bell numbers B(n)B(n). Prove that B(x)=eex1B(x)=e^{e^x-1}.

Solution

We know that B(n+1)=i=0nB(i)(ni)B(n+1)=\sum_{i=0}^n B(i)\left(\begin{array}{l}n \\ i\end{array}\right) if n0n \geq 0, and B(0)=1B(0)=1. Multiply both sides by xn/nx^n / n ! and sum over all n0n \geq 0 to get

n0B(n+1)xnn!=n0i=0nB(i)(ni)xnn!.\sum_{n \geq 0} B(n+1) \frac{x^n}{n !}=\sum_{n \geq 0} \sum_{i=0}^n B(i)\left(\begin{array}{c} n \\ i \end{array}\right) \frac{x^n}{n !} .

Now note that the left-hand side is B(x)B^{\prime}(x), while the right-hand side is B(x)exB(x) e^x (proof is skipped). Therefore, we get

B(x)=B(x)ex,B(x)B(x)=ex,\begin{gathered} B^{\prime}(x)=B(x) e^x, \\ \frac{B^{\prime}(x)}{B(x)}=e^x, \end{gathered}

and, taking integrals,

lnB(x)=ex+C.\ln B(x)=e^x+C .

Setting x=0x=0, the left-hand side is ln1=0\ln 1=0, therefore we must choose C=C= 1-1 on the right-hand side. Therefore, lnB(x)=ex1\ln B(x)=e^x-1, and B(x)=eex1B(x)=e^{e^x-1} as claimed.